package com.zlj.listener;

import java.util.LinkedHashMap;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
public class ListenerDemo implements ServletContextListener {

    public void contextDestroyed(ServletContextEvent sce)  { 
    }

    /**
     * 在服务器启动时创建Map，保存到ServletContext中
     */
    public void contextInitialized(ServletContextEvent sce)  {
    	
    	//创建map,键为IP,值为统计的访问IP次数
    	Map<String,Integer> map = new LinkedHashMap<String,Integer>();
    	
    	//获取ServletContext
    	ServletContext application = sce.getServletContext();
    	
    	//把map保存到ServletContext中
    	application.setAttribute("map", map);
    }
}
